package com.iqiyi.pps.epg.core.utils;

import java.text.NumberFormat;

/**
 * Created by zhang on 2016/4/27.
 */
public class MathUtils {

    /**
     * 求百分比，保留2位小数
     * @param numbers
     * @param total
     * @return
     */
    public static String percent(long numbers, long total, int Digits) {
        // 创建一个数值格式化对象
        NumberFormat numberFormat = NumberFormat.getInstance();
        // 设置精确到小数点后2位
        numberFormat.setMaximumFractionDigits(Digits);
        String result = "";
        if (total == 0) {
            result = "0";
        } else {
            result = numberFormat.format((float) numbers / (float) total * 100);
        }
        return result + "%";
    }
}
